﻿#region Using Directives

using System;
using System.Web;
using System.Web.Security;
using System.Configuration;
using QuickDev.Localization;
using QuickDev.BLL;
using QuickDev.Web.UI;
using QuickDev.Caching;
using QuickDev.Web.UI.Controls;
using QuickDev.Common.Audit;
using QuickDev.SSO;

#endregion

namespace QuickDev.Web.App.Administration.Controls.Authentication
{
    public partial class AuthenticatedUser : AdminControl
    {
        #region Page Events

        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        protected void Page_Load( object sender, EventArgs e )
        {
            SetAuthenticatedUserProperties();
        }

        /// <summary>
        /// Handles the Click event of the lnkLogout control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        protected void lnkLogout_Click( object sender, EventArgs e )
        {
            try
            {
                //TODO: CMC - Put in cookie stuff 
                FormsAuthentication.SignOut();
                SsoEngine.SignOut();
            }
            catch ( System.Threading.ThreadAbortException )
            {
                //ignore error.
            }
            catch ( Exception ex )
            {
                Logger.Error( typeof( AuthenticatedUser ).Name + ".lnkLogout_Click", ex );
            }
        }

        #endregion

        #region Methods

        #region Private

        /// <summary>
        /// Sets the authenticated user properties.
        /// </summary>
        private void SetAuthenticatedUserProperties()
        {
            hlApplications.NavigateUrl = ConfigurationManager.AppSettings["APP_Url"];
        }

        #endregion

        #endregion
    }
}